from django.db import models
from django.utils import timezone

class ProductInventoryLog(models.Model):
    sku = models.CharField(max_length=50, verbose_name="产品SKU")
    box_spec = models.IntegerField(verbose_name="箱规")
    box_count = models.IntegerField(verbose_name="箱数")
    date = models.DateField(default=timezone.now, verbose_name="日期")
    remark = models.TextField(blank=True, null=True, verbose_name="备注")

    class Meta:
        verbose_name = "产品库存日志"
        verbose_name_plural = "产品库存日志"

    def __str__(self):
        return f"{self.sku} - {self.box_spec} - {self.box_count}箱"


class MaterialInventoryLog(models.Model):
    sku = models.CharField(max_length=50, verbose_name="物料SKU")
    pcs_count = models.IntegerField(verbose_name="件数")
    date = models.DateField(default=timezone.now, verbose_name="日期")
    remark = models.TextField(blank=True, null=True, verbose_name="备注")

    class Meta:
        verbose_name = "物料库存日志"
        verbose_name_plural = "物料库存日志"

    def __str__(self):
        return f"{self.sku} - {self.pcs_count}件"


# 产品物料关系表 (用于备货计算)
class ProductMaterialRelation(models.Model):
    product_sku = models.CharField(max_length=50, verbose_name="产品SKU")
    material_sku = models.CharField(max_length=50, verbose_name="物料SKU")
    material_quantity = models.IntegerField(verbose_name="物料数量")

    class Meta:
        verbose_name = "产品物料关系"
        verbose_name_plural = "产品物料关系"

    def __str__(self):
        return f"{self.product_sku}需要{self.material_quantity}个{self.material_sku}"